import Vue from 'vue'
import App from './App.vue'

import axios from 'axios'
Vue.prototype.$http = axios
// 加载bootstrap
import 'bootstrap/dist/css/bootstrap.min.css'
// 加载字体图标库
import 'font-awesome/css/font-awesome.min.css'
import store from './vuex/store.js'
// 加载自定义接口随机生成的数据
import Mock from './mock/Mock.js'

import VueRouter from 'vue-router'

// 加载elementui
import ElementUi from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(ElementUi)
import {
    Loading
} from 'element-ui'

// 加载路由文件
import routes from './router/router.js'

// 用vue-router使用路由文件
const router = new VueRouter({
    routes,
    'linkActiveClass': 'active'
})
// 全局导航守卫
router.beforeEach((to, from, next) => {
    var token = store.state.username
    var str = 'table'
    // 假如路由在table且没有token值就改变
    if (to.path == '/') {
        console.log(to, 1)
        if (token === "") {
            router.push({
                path: '/login'
            })
        }
    }
    // if (to.name === 'login') {
    //     if (token) {
    //         console.log('来')
    //         router.push({
    //             path: '/table'
    //         })
    //     }
    // }
    // 进行管道的下一个钩子
    next()
});



let loadingInstance
axios.interceptors.request.use((config) => {
    loadingInstance = Loading.service({
        fullscren: true
    })
    return config
})
axios.interceptors.response.use((data) => {
    loadingInstance.close({
        fullscren: true
    })
    return data
})

Vue.use(VueRouter)
// Vue.use()
var vm = new Vue({
    el: '#app',
    // render: c => c(App),
    router,
    store
})
export default vm